import tkinter as tk
from dataclasses import asdict

from Attriabte.DTO import BasicWidgetDto


class BasicHoverLabel:
    """
    鼠标移动到Label有反应一定的Label
    """

    def __init__(self, win, config: BasicWidgetDto, clicked=None):
        self.arg = (win, config)
        self.label = tk.Label(win, config.todict())
        def pass_do():
            print("被点击")
        if clicked:
            self.click = lambda e:clicked()
        else:
            self.click = lambda e:pass_do()
        self.__bind_mouse()

    def __bind_mouse(self):
        """
        bind mouse event to label.
        :return: None
        """
        self.label.bind("<Enter>", lambda e: self.hover(e))
        self.label.bind("<Leave>", lambda e: self.leave(e))
        self.label.bind("<Button-1>", lambda e: self.click(e))

    def hover(self, e):
        print("label enter")

    def leave(self, e):
        print("label leave")
        self.__init__(*self.arg)

    def get(self):
        return self.label
